package com.pic4493.app;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.pic4493.base.BaseUITopBar;
import com.pic4493.comm.Session;
import com.pic4493.entities.DJson;
import com.pic4493.entities.EUser;
import com.pic4493.net.NetClientJ;
import com.pic4493.utils.UtiDialog;

public class UIAdvise extends BaseUITopBar
{
   private Context mContext = UIAdvise.this;
   private EditText mEdtContent;
   private String content;

   private void initView()
   {
	  mImgRight.setVisibility(View.VISIBLE);
	  mEdtContent = (EditText) findViewById(R.id.uiadvise_edt_content);
   }

   private void initEvent()
   {
	  mImgRight.setOnClickListener(new View.OnClickListener()
	  {
		 @Override
		 public void onClick(View v)
		 {
			if (mEdtContent != null && mEdtContent.getText() != null)
			{
			   if ("".equals(mEdtContent.getText().toString()))
			   {
				  UtiDialog.getInstance().ShowToastInfoShort(mContext, "内容不能为空");
				  return;
			   }
			   else
			   {
				  content = mEdtContent.getText().toString();
				  executeAsyncTask("upload");
			   }
			}
		 }
	  });
   }

   @Override
   protected void onCreate(Bundle savedInstanceState)
   {
	  setContentView(R.layout.uiadvise);
	  super.onCreate(savedInstanceState);

	  setTitle("建议");

	  initView();
	  initEvent();

   }

   @Override
   public void onAsyncTaskStart(String taskName, Object[] params)
   {
	  UtiDialog.getInstance().ShowLoadingDialogNoTitleEX(mContext, "提交中...");
   }

   @Override
   public Object onAsyncTaskInBackground(String taskName, Object[] params) throws Exception
   {
	  if ("upload".equals(taskName))
	  {
		 return NetClientJ.Advise(content);
	  }
	  return null;
   }

   @Override
   public void onAsyncTaskEnd(String taskId, String taskName, Object[] params, Object result)
   {
	  try
	  {
		 UtiDialog.getInstance().DismissLoadingDialog();
		 if (result != null)
		 {
			DJson data = (DJson) result;
			if (!data.getHead().hasError())
			{
                UtiDialog.getInstance().ShowToastInfoShort(mContext, "提交成功,感谢您的支持");
                finish();
			}
			else
			{
			   UtiDialog.getInstance().ShowToastInfoLong(mContext, data.getHead().getRspMsg());
			}
		 }
		 else
		 {
			UtiDialog.getInstance().ShowToastInfoLong(mContext, "网络异常请稍候再试");
		 }
	  }
	  catch (Exception e)
	  {
		 Log.d("ERROR", "UIAdvise_onAsyncTaskEnd(taskId, taskName, params, result) " + e);
	  }
   }
}
